package com.custom.tab;

import com.tos.quran.QuranActivity;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.View;

public class AbstractViewController {

	private AbstractTabRootManager tabRootManager;
	private QuranActivity activity;
	private View mainView;

	public AbstractViewController(AbstractTabRootManager tabRootManager,
			int layoutId) {
		try {
			this.tabRootManager = tabRootManager;
			this.activity = tabRootManager.getActivity();
			mainView = tabRootManager.getLayoutInflater().inflate(layoutId, null,
					false);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public AbstractTabRootManager getTabRootManager() {
		return tabRootManager;
	}

	public QuranActivity getActivity() {
		return activity;
	}

	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
	}

	public void onConfigurationChanged(Configuration newConfig) {

	}

	public void broadcastMessageReceived(String key, String message) {
	}

	public boolean onBackPressed() {
		return false;
	}

	public void finish() {
		try {
			getActivity().onBackPressed();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void onDestroy() {

	}

	public void pushViewController(
			AbstractViewController viewControllerInterface) {
		tabRootManager.pushViewController(viewControllerInterface);
	}

	public void pushViewControllerClearingAll(
			AbstractViewController viewControllerInterface) {
		tabRootManager.pushViewControllerClearingAll(viewControllerInterface);
	}

	public void onResume() {
	}

	public void onPause() {
	}

	public View getView() {
		return mainView;
	}

	public void startActivityForResult(Intent intent, int requestCode) {
		tabRootManager.getActivity().startActivityForResult(intent,
				requestCode, this);
	}

	public SharedPreferences getSharedPreferences() {
		return tabRootManager.getSharedPreferences();
	}

	public String getString(int resId) {
		return activity.getString(resId);
	}

	public void sendBroadcastMessage(String key, String message) {
		activity.sendBroadcastMessage(key, message);
	}

	public Resources getResources() {
		return activity.getResources();
	}

	public ContentResolver getContentResolver() {
		return activity.getContentResolver();
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	}

	public View findViewById(int id) {
		View ret = null;
		try {
			if (mainView != null) {
				ret = mainView.findViewById(id);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret;
	}

	public void back(int n) {
		tabRootManager.back(n);
	}
	
	public boolean isLandscape(){
		return getActivity().isLandscape();
	}
	public boolean isPortrait(){
		return getActivity().isPortrait();
	}
}
